package com.ahnu.tongue.controller;

import com.ahnu.tongue.annotation.OperationLog;
import com.ahnu.tongue.common.Result;
import com.ahnu.tongue.dto.LoginResponse;
import com.ahnu.tongue.dto.WxLoginRequest;
import com.ahnu.tongue.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(tags = "认证接口", description = "包含用户登录相关接口")
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
@Validated
public class AuthController {

    private final UserService userService;

    @ApiOperation(value = "微信小程序登录", notes = "通过微信小程序的code进行登录，返回token和用户信息")
    @PostMapping("/login")
    @OperationLog(operationType = "LOGIN", description = "微信小程序用户登录")
    public Result<LoginResponse> login(@Valid @RequestBody WxLoginRequest request) {
        return Result.success(userService.wxLogin(request));
    }
} 